package pack0902;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class DemoC2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        try {
            Socket socket = new Socket("192.168.1.161",9989);
            System.out.println("已经连接客户端");
            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();

            byte[] bytes = new byte[100];
            while (true){
                int len = is.read(bytes);
                String str = new String(bytes,0,len);
                System.out.println(str);

                String str1 = in.next();
                if ("exit".equals(str1)){
                    break;
                }
                os.write(str1.getBytes());
            }
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}
